/**
 * @author : cyb1010
 * @date   : 2024-06-11 10:15:13
 * @file   : stamp.cpp
 */
#include <bits/stdc++.h>
using namespace std;
#define fo(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
#define fi first
#define se second
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) int(v.size())
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
void ckmx(int &x, int y) { x < y && (x = y); }
void ckmn(int &x, int y) { x > y && (x = y); }
const int N = 6000010, dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};

int __, n, m, k, sx, sy, px, py;
string s[N];

int bufr[N], *r[N], *nr = bufr;
int bufd[N], *d[N], *nd = bufd;
int findr(int x, int y) {
    if (y >= m) return y;
    return r[x][y] == y ? y : (r[x][y] = findr(x, r[x][y]));
}
int findd(int x, int y) {
    if (x >= n) return x;
    return d[y][x] == x ? x : (d[y][x] = findd(d[y][x], y));
}

int bufs[N], *dis[N], *nwd = bufs;

int main() {
    fo("stamp");
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m >> k >> sx >> sy >> px >> py;
    for (int i = 0; i < n; i++) cin >> s[i];

    sx--, sy--, px--, py--;
    for (int i = 0; i < n; i++) r[i] = nr, nr += m, iota(r[i], nr, 0);
    for (int i = 0; i < m; i++) d[i] = nd, nd += n, iota(d[i], nd, 0);

    memset(bufs, 0x3f, sizeof(bufs));
    for (int i = 0; i < n; i++) dis[i] = nwd, nwd += m;

    int ans = dis[0][0];
    queue<P> q;
    auto psb = [&](int x, int y, int w) {
        r[x][y] = y + 1, d[y][x] = x + 1, dis[x][y] = w, q.emplace(x, y);
    };
    auto ins = [&](int x, int y, int w) {
        queue<P> s;
        psb(x, y, w), s.emplace(x, y);
        while (!s.empty()) {
            auto [x, y] = s.front();
            s.pop();
            for (int i = 0; i < 4; i++) {
                int tx = x + dx[i], ty = y + dy[i];
                if (tx >= 0 && tx < n && ty >= 0 && ty < m && ::s[tx][ty] == '.'
                    && r[tx][ty] == ty)
                    psb(tx, ty, w), s.emplace(tx, ty);
            }
        }
    };
    ins(sx, sy, 0);
    while (!q.empty()) {
        auto [x, y] = q.front();
        q.pop();
        if (x == px && y == py) break;
        if (max(abs(x - px), abs(y - py)) <= k + 1
            && (abs(x - px) + abs(y - py)) <= n * 2) {
            ans = dis[x][y] + 1;
            break;
        }
        int tx, ty;
        const int ex = min(n, x + k), ey = min(m, y + k);
        // (x-k,(y-k+1)~(y+k-1))
        tx = max(x - k, 0), ty = findr(tx, max(y - k + 1, 0));
        while (ty < ey) ins(tx, ty, dis[x][y] + 1), ty = findr(tx, ty);
        // (x+k,(y-k+1)~(y+k-1))
        tx = min(x + k, n - 1), ty = findr(tx, max(y - k + 1, 0));
        while (ty < ey) ins(tx, ty, dis[x][y] + 1), ty = findr(tx, ty);
        // ((x-k+1)~(x+k-1),y-k)
        ty = max(y - k, 0), tx = findd(max(x - k + 1, 0), ty);
        while (tx < ex) ins(tx, ty, dis[x][y] + 1), tx = findd(tx, ty);
        // ((x-k+1)~(x+k-1),y+k)
        ty = min(y + k, m - 1), tx = findd(max(x - k + 1, 0), ty);
        while (tx < ex) ins(tx, ty, dis[x][y] + 1), tx = findd(tx, ty);
    }
    cout << min(ans, dis[px][py]) << '\n';
    return 0 ^ __ ^ 0;
}